function insertdata()
{
	var key = "4c6e4353798333648403e6430c9e6589";
	var month = $("#month").val();
	var day = $("#day").val();
	$.ajax({
		dataType:'JSONP',
		url:"http://v.juhe.cn/todayOnhistory/queryEvent.php?key="+key+"&date="+month+"/"+day,
		type:'GET',
		async:true,
		jsonp:'callback',
		success:function(res){
			var show = "<table class='table  table-striped table-bordered'>";
			show += "<tr> <td>时间</td> <td>事件</td> </tr>";
			for(var i = 0;i < 5 ;i++)
			{							
			  show += "<tr><td>"+res.result[i].date+"</td>";
			  show += "<td>"+res.result[i].title+"</td>";
			  //show += "<td>"+result.result[1].des+"</td>";
			  show += "</tr>";
			}
			show += "</table>";
			show += "<tr><td><b>只是列举了5个，还有很多......</b></td></tr>"
			$("#pos").after(show);
		},
	});
}

function check()
{
	var username=sessionStorage.key(sessionStorage.length);
    if(sessionStorage.length==0)
	{
		alert("非法访问！");
		//window.location.href='http://butui.gitee.io/test_pages/';
		self.location.href="http://butui.gitee.io/test_pages/";
	}
    else 
    { 
    	var list = document.getElementById("yesname"); 
        list.innerHTML =sessionStorage.getItem("username");
		load();
	}
}

function load()
{  
    var list = document.getElementById("list");  
        if(localStorage.length>0){  
            var results = "<table class='table  table-striped table-bordered'>";  
            results += "'<tr><td>用户名</td><td>邮箱</td><td>注册时间</td></tr>'";  
            for(var i=0;i<localStorage.length;i++)
			{  				
				{	
                	var sitename = localStorage.key(i);  
                	var str = localStorage.getItem(sitename);                 
                	//var site = localStorage.getItem(sitename);  
					var site = JSON.parse(str);
                	results += "<tr><td>"+sitename+"</td><td>"+site.sitename+"</td><td>"+site.nowtime+"</td></tr>";  
                }	
            }  
            results += "</table>";  
            list.innerHTML = results;  
        }else{  
            list.innerHTML = "数据为空……";  
        }  
}      

//保存注册信息到Localstorage
function save(){  
    var x = new Object;	
    x.keyname = document.getElementById("acc").value;
    x.sitename = document.getElementById("email").value;  
    x.siteurl = document.getElementById("pd").value;
	var d=new Date();
	x.nowtime=d.toLocaleDateString();
    var str = JSON.stringify(x); // 将对象转换为字符串
    localStorage.setItem(x.keyname,str);  	
    alert("注册成功");
	//self.location.href="http://butui.gitee.io/test_pages/";	
	self.location.href="http://butui.gitee.io/test_pages/";	
	//return true;
}

function match(){
	var account = document.getElementById("acc").value;
	var str = localStorage.getItem(account);

	if (str==null){
		alert("不存在此用户");
		return false;
	}

	var site = JSON.parse(str);

	if (document.getElementById("pw").value!=site.siteurl){
		alert("密码错误");
		return false;
	}

	sessionStorage.username = account;
	//window.location.href='http://butui.gitee.io/test_pages/success.html';
	window.location.href='http://butui.gitee.io/test_pages/success.html';
}

function validate_required(value,alerttxt)
{

if (value==null||value=="")
  {alert(alerttxt);return false}
else {return true}

}

function validateForm()
{	
	var x=document.forms["Form"]["acc"].value;
	if (validate_required(x,"请输入用户名")==false) return false;	
    var siteurl = localStorage.getItem(x);  
    if(siteurl!=null)
    {
		alert("用户名已使用");
		return false;
	}
	   
	var x=document.forms["Form"]["email"].value;
	if (validate_required(x,"请输入邮箱")==false) return false;
	var atpos=x.indexOf("@");	
	var dotpos=x.lastIndexOf(".");
	if ((atpos<1 )||(dotpos<atpos+2)||(dotpos+2>=x.length))
	{
		alert("不是一个有效的 e-mail 地址");
	    return false;
	}
	
	var x=document.forms["Form"]["pd"].value;
	if (validate_required(x,"请输入密码")==false) return false;
	
	var x=document.forms["Form"]["pd1"].value;	
	if (validate_required(x,"请确认密码")==false) return false;	
	
	if (x != document.forms["Form"]["pd"].value)
	{
		alert("两次密码输入不一致");
		return false;
	}	
}

//CharMode函数  测试某个字符是属于哪一类.  
function CharMode(iN)
{  
	if (iN>=48 && iN <=57) //数字  
		return 1;  
	if (iN>=65 && iN <=90) //大写字母  
		return 2;  
	if (iN>=97 && iN <=122) //小写  
		return 4;  
	else  
		return 8; //特殊字符  
}  

//bitTotal函数  计算出当前密码当中一共有多少种模式  
function bitTotal(num){  
	modes=0;  
	for (i=0;i<4;i++)
	{  
		if (num & 1) modes++;  
		num>>>=1;  
	}  
	return modes;  
}  

//checkStrong函数  
//返回密码的强度级别  

function checkStrong(pd)
{  
	if (pd.length<=4) return 0; //密码太短  
	Modes=0;  
	for (i=0;i<pd.length;i++)
	{  
		//测试每一个字符的类别并统计一共有多少种模式.  
		Modes|=CharMode(pd.charCodeAt(i));  
	}  
	return bitTotal(Modes);  
}  

//pwStrength函数  
//当用户放开键盘或密码输入框失去焦点时,根据不同的级别显示不同的颜色  
function pwStrength(pd)
{  
	O_color="#eeeeee";  
	L_color="#FF0000";  
 	M_color="#FF9900";  
	H_color="#33CC00";  

	if ((pd==null)||(pd==''))
	{  
		Lcolor=Mcolor=Hcolor=O_color;  
    }  
	else
	{  
		S_level=checkStrong(pd);  
		switch(S_level) 
		{  
			case 0:  
				Lcolor=Mcolor=Hcolor=O_color;  
			case 1:  
				Lcolor=L_color;  
				Mcolor=Hcolor=O_color;  
				break;  
			case 2:  
				Lcolor=Mcolor=M_color;  
				Hcolor=O_color;  
				break;  
			default:  
				Lcolor=Mcolor=Hcolor=H_color;  
		}  
	}  

	document.getElementById("strength_L").style.background=Lcolor;  
	document.getElementById("strength_M").style.background=Mcolor;  
	document.getElementById("strength_H").style.background=Hcolor;  
	return;  
}  